<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class media_env_urban_manage extends CI_Controller {


	public function __construct() {
		session_start();
		parent::__construct();
		$this->load->helper("common");
	}

	public function  index(){
		$this->env_urban_circle();
	}
	public function env_urban_circle(){


		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}
		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");



		$this->load->library("env/urban_circle");
		$data['urban_circle_list'] 	=$this->urban_circle->query_urban_circle_list($_SESSION['user_id'],$search);
		$data['num']				=$this->urban_circle->query_urban_circle_num($_SESSION['user_id'],$search);



		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}

		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_circle?".$search_url,$data['num']);

		$this->load->view("media/env_urban/env_urban_circle",$data);
	}
	public function add_env_urban_circle(){


		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_circle",$data);
	}
	public function save_env_urban_circle(){

		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =trim($this->input->post("level"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['core_area'] =trim($this->input->post("core_area"));
		$env['subway_station'] =trim($this->input->post("subway_station"));
		$env['market'] =trim($this->input->post("market"));
		$env['shopping_store'] =trim($this->input->post("shopping_store"));
		$env['office'] =trim($this->input->post("office"));
		$env['college'] =trim($this->input->post("college"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['hospital'] =trim($this->input->post("hospital"));
		$env['community'] =trim($this->input->post("community"));
		$env['env_desc'] =trim($this->input->post("env_desc"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_circle");
		$result =$this->urban_circle->save_env_urban_circle($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_circle(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");

		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"circle","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"circle","led");

		$this->load->library("env/urban_circle");
		$data['env_urban_circle_info']=$this->urban_circle->query_env_urban_circle($env_id);

		$this->load->view("media/env_urban/query_env_urban_circle",$data);
	}


	public function edit_env_urban_circle(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_circle");
		$data['env_urban_circle_info']=$this->urban_circle->query_env_urban_circle($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_circle_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_circle_info']['province']);
		}
		if($data['env_urban_circle_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_circle_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_circle",$data);
	}

	public function update_env_urban_circle(){

		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env_id =$this->input->post('env_id');
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =trim($this->input->post("level"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['core_area'] =trim($this->input->post("core_area"));
		$env['subway_station'] =trim($this->input->post("subway_station"));
		$env['market'] =trim($this->input->post("market"));
		$env['shopping_store'] =trim($this->input->post("shopping_store"));
		$env['office'] =trim($this->input->post("office"));
		$env['college'] =trim($this->input->post("college"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['hospital'] =trim($this->input->post("hospital"));
		$env['community'] =trim($this->input->post("community"));
		$env['env_desc'] =trim($this->input->post("env_desc"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_circle");
		$result =$this->urban_circle->update_env_urban_circle($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function delete_env_urban_circle() {
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();


		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		$this->load->library("env/urban_circle");
		$env_id =$this->input->get('env_id');
		$this->urban_circle->delete_env_urban_circle($env_id);
		echo "<script>history.go(-1)</script>";
	}


	public function env_urban_road(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}

		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");



		$this->load->library("env/urban_road");
		$data['urban_road_list'] 	=$this->urban_road->query_urban_road_list($_SESSION['user_id'],$search);
		$data['num']				=$this->urban_road->query_urban_road_num($_SESSION['user_id'],$search);



		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}

		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_road?".$search_url,$data['num']);

		$this->load->view("media/env_urban/env_urban_road",$data);
	}


	public function add_env_urban_road(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_road",$data);
	}

	public function save_env_urban_road(){


		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =$this->input->post("region");
		$env['road_length'] =trim($this->input->post("road_length"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =trim($this->input->post("level"));
		$env['circle'] =trim($this->input->post("circle"));
		$env['professional_market'] =trim($this->input->post("professional_market"));
		$env['venues'] =trim($this->input->post("venues"));
		$env['starting_position'] =trim($this->input->post("starting_position"));
		$env['subway_station'] =trim($this->input->post("subway_station"));
		$env['market'] =trim($this->input->post("market"));
		$env['office'] =trim($this->input->post("office"));
		$env['attractions'] =trim($this->input->post("attractions"));
		$env['college'] =trim($this->input->post("college"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['hospital'] =trim($this->input->post("hospital"));
		$env['community'] =trim($this->input->post("community"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_road");
		$result =$this->urban_road->save_env_urban_road($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_road(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_road");
		$data['env_urban_road_info']=$this->urban_road->query_env_urban_road($env_id);

		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"road","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"road","led");

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_road_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_road_info']['province']);
			$data['last_regions'] =$this->region->get_regions($data['env_urban_road_info']['city']);
		}
		$data['region_list'] =$this->urban_road->query_env_urban_road_region($env_id);
		$this->load->view("media/env_urban/query_env_urban_road",$data);
	}
	public function edit_env_urban_road() {

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_road");
		$data['env_urban_road_info']=$this->urban_road->query_env_urban_road($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_road_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_road_info']['province']);
			$data['last_regions'] =$this->region->get_regions($data['env_urban_road_info']['city']);
		}
		$data['region_list'] =$this->urban_road->query_env_urban_road_region($env_id);
		$this->load->view("media/env_urban/edit_env_urban_road",$data);
	}

	public function update_env_urban_road(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();

		}
		$env_id=$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =$this->input->post("region");
		$env['road_length'] =trim($this->input->post("road_length"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =trim($this->input->post("level"));
		$env['circle'] =trim($this->input->post("circle"));
		$env['professional_market'] =trim($this->input->post("professional_market"));
		$env['venues'] =trim($this->input->post("venues"));
		$env['starting_position'] =trim($this->input->post("starting_position"));
		$env['subway_station'] =trim($this->input->post("subway_station"));
		$env['market'] =trim($this->input->post("market"));
		$env['office'] =trim($this->input->post("office"));
		$env['attractions'] =trim($this->input->post("attractions"));
		$env['college'] =trim($this->input->post("college"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['hospital'] =trim($this->input->post("hospital"));
		$env['community'] =trim($this->input->post("community"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_road");
		$result =$this->urban_road->update_env_urban_road($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);

	}

	public function delete_env_urban_road(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_urban_env",$_SESSION['user_id'])) {

			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		$this->load->library("env/urban_road");
		$env_id =$this->input->get('env_id');
		$this->urban_road->delete_env_urban_road($env_id);
		echo "<script>history.go(-1)</script>";

	}

	public function env_urban_market(){


		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}

		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");



		$this->load->library("env/urban_market");
		$data['urban_market_list'] 	=$this->urban_market->query_urban_market_list($_SESSION['user_id'],$search);
		$data['num']				=$this->urban_market->query_urban_market_num($_SESSION['user_id'],$search);



		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}

		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_market?".$search_url,$data['num']);

		$this->load->view("media/env_urban/env_urban_market",$data);
	}

	public function add_env_urban_market(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_market",$data);
	}
	public function save_env_urban_market(){

		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =trim($this->input->post("level"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['title'] =trim($this->input->post("title"));
		$env['subway_station'] =trim($this->input->post("subway_station"));
		$env['env_desc'] =trim($this->input->post("env_desc"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_market");
		$result =$this->urban_market->save_env_urban_market($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_market(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_market");
		$data['env_urban_market_info']=$this->urban_market->query_env_urban_market($env_id);

		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"market","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"market","led");


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_market_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_market_info']['province']);
		}
		if($data['env_urban_market_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_market_info']['city']);
		}
		$this->load->view("media/env_urban/query_env_urban_market",$data);
	}
	public function edit_env_urban_market(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {

			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_market");
		$data['env_urban_market_info']=$this->urban_market->query_env_urban_market($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_market_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_market_info']['province']);
		}
		if($data['env_urban_market_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_market_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_market",$data);
	}

	public function update_env_urban_market(){

		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {

			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env_id =$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =trim($this->input->post("level"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['title'] =trim($this->input->post("title"));
		$env['subway_station'] =trim($this->input->post("subway_station"));
		$env['env_desc'] =trim($this->input->post("env_desc"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_market");
		$result =$this->urban_market->update_env_urban_market($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_env_urban_market(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_urban_env",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("env/urban_market");
		$env_id =$this->input->get('env_id');
		$this->urban_market->delete_env_urban_market($env_id);
		echo "<script>history.go(-1)</script>";

	}

	public function env_urban_station(){


		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}

		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");



		$this->load->library("env/urban_station");
		$data['urban_station_list'] 	=$this->urban_station->query_urban_station_list($_SESSION['user_id'],$search);
		$data['num']					=$this->urban_station->query_urban_station_num($_SESSION['user_id'],$search);



		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}

		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_station?".$search_url,$data['num']);

		$this->load->view("media/env_urban/env_urban_station",$data);
	}

	public function add_env_urban_station(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_station",$data);
	}

	public function save_env_urban_station(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();

		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =$this->input->post("level");
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['departure_range'] =trim($this->input->post("departure_range"));
		$env['stops'] =trim($this->input->post("stops"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_station");
		$result =$this->urban_station->save_env_urban_station($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_station(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_station");
		$data['env_urban_station_info']=$this->urban_station->query_env_urban_station($env_id);

		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"station","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"station","led");

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_station_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_station_info']['province']);
		}
		if($data['env_urban_station_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_station_info']['city']);
		}
		$this->load->view("media/env_urban/query_env_urban_station",$data);
	}
	public function edit_env_urban_station(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_station");
		$data['env_urban_station_info']=$this->urban_station->query_env_urban_station($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_station_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_station_info']['province']);
		}
		if($data['env_urban_station_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_station_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_station",$data);
	}

	public function update_env_urban_station(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}

		$env_id =$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['level'] =$this->input->post("level");
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['departure_range'] =trim($this->input->post("departure_range"));
		$env['stops'] =trim($this->input->post("stops"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_station");
		$result =$this->urban_station->update_env_urban_station($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_env_urban_station(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_urban_env",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		$this->load->library("env/urban_station");
		$env_id =$this->input->get('env_id');
		$this->urban_station->delete_env_urban_station($env_id);
		echo "<script>history.go(-1)</script>";

	}

	public function env_urban_stop(){


		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}

		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");



		$this->load->library("env/urban_stop");
		$data['urban_stop_list'] 	=$this->urban_stop->query_urban_stop_list($_SESSION['user_id'],$search);
		$data['num']				=$this->urban_stop->query_urban_stop_num($_SESSION['user_id'],$search);



		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}

		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_stop?".$search_url,$data['num']);

		$this->load->view("media/env_urban/env_urban_stop",$data);
	}

	public function add_env_urban_stop(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_stop",$data);
	}

	public function save_env_urban_stop(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();

		}

		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['departure_range'] =trim($this->input->post("departure_range"));
		$env['stops'] =trim($this->input->post("stops"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_stop");
		$result =$this->urban_stop->save_env_urban_stop($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_stop(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_stop");
		$data['env_urban_stop_info']=$this->urban_stop->query_env_urban_stop($env_id);

		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"stop","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"stop","led");

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_stop_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_stop_info']['province']);
		}
		if($data['env_urban_stop_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_stop_info']['city']);
		}
		$this->load->view("media/env_urban/query_env_urban_stop",$data);
	}
	public function edit_env_urban_stop(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_stop");
		$data['env_urban_stop_info']=$this->urban_stop->query_env_urban_stop($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_stop_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_stop_info']['province']);
		}
		if($data['env_urban_stop_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_stop_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_stop",$data);
	}

	public function update_env_urban_stop(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env_id =$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['departure_range'] =trim($this->input->post("departure_range"));
		$env['stops'] =trim($this->input->post("stops"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_stop");
		$result =$this->urban_stop->update_env_urban_stop($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_env_urban_stop(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("delete_urban_env",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}
		$this->load->library("env/urban_stop");
		$env_id =$this->input->get('env_id');
		$this->urban_stop->delete_env_urban_stop($env_id);
		echo "<script>history.go(-1)</script>";

	}


	public function env_urban_venues(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}

		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");
		
		
		$this->load->library("env/urban_venues");
		$data['urban_venues_list'] 	=$this->urban_venues->query_urban_venues_list($_SESSION['user_id'],$search);
		$data['num']				=$this->urban_venues->query_urban_venues_num($_SESSION['user_id'],$search);



		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}

		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_venues?".$search_url,$data['num']);

		$this->load->view("media/env_urban/env_urban_venues",$data);
	}

	public function add_env_urban_venues(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_venues",$data);
	}

	public function save_env_urban_venues(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['event'] =trim($this->input->post("event"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_venues");
		$result =$this->urban_venues->save_env_urban_venues($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_venues(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_venues");
		$data['env_urban_venues_info']=$this->urban_venues->query_env_urban_venues($env_id);


		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"venues","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"venues","led");

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_venues_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_venues_info']['province']);
		}
		if($data['env_urban_venues_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_venues_info']['city']);
		}
		$this->load->view("media/env_urban/query_env_urban_venues",$data);
	}
	public function edit_env_urban_venues(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_venues");
		$data['env_urban_venues_info']=$this->urban_venues->query_env_urban_venues($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_venues_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_venues_info']['province']);
		}
		if($data['env_urban_venues_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_venues_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_venues",$data);
	}

	public function update_env_urban_venues(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}

		$env_id =$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['region_type'] =trim($this->input->post("region_type"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['event'] =trim($this->input->post("event"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_venues");
		$result =$this->urban_venues->update_env_urban_venues($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_env_urban_venues(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("env/urban_venues");
		$env_id =$this->input->get('env_id');
		$this->urban_venues->delete_env_urban_venues($env_id);
		echo "<script>history.go(-1)</script>";
	}




	public function env_urban_cbd(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}
		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");
		
		
		$this->load->library("env/urban_cbd");
		$data['urban_cbd_list'] 	=$this->urban_cbd->query_urban_cbd_list($_SESSION['user_id'],$search);
		$data['num']				=$this->urban_cbd->query_urban_cbd_num($_SESSION['user_id'],$search);



		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}

		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_cbd?".$search_url,$data['num']);

		$this->load->view("media/env_urban/env_urban_cbd",$data);
	}

	public function add_env_urban_cbd(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_cbd",$data);
	}

	public function save_env_urban_cbd(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['building'] =trim($this->input->post("building"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['enterprise'] =trim($this->input->post("enterprise"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['subway_station'] =trim($this->input->post("subway_station"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_cbd");
		$result =$this->urban_cbd->save_env_urban_cbd($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_cbd(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_cbd");
		$data['env_urban_cbd_info']=$this->urban_cbd->query_env_urban_cbd($env_id);


		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"cbd","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"cbd","led");

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_cbd_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_cbd_info']['province']);
		}
		if($data['env_urban_cbd_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_cbd_info']['city']);
		}
		$this->load->view("media/env_urban/query_env_urban_cbd",$data);
	}
	public function edit_env_urban_cbd(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_cbd");
		$data['env_urban_cbd_info']=$this->urban_cbd->query_env_urban_cbd($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_cbd_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_cbd_info']['province']);
		}
		if($data['env_urban_cbd_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_cbd_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_cbd",$data);
	}

	public function update_env_urban_cbd(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}

		$env_id =$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['building'] =trim($this->input->post("building"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['enterprise'] =trim($this->input->post("enterprise"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['subway_station'] =trim($this->input->post("subway_station"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_cbd");
		$result =$this->urban_cbd->update_env_urban_cbd($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_env_urban_cbd(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("env/urban_cbd");
		$env_id =$this->input->get('env_id');
		$this->urban_cbd->delete_env_urban_cbd($env_id);
		echo "<script>history.go(-1)</script>";
	}


	public function env_urban_chief_district(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}
		
		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");
		
		
		$this->load->library("env/urban_chief_district");
		$data['urban_chief_district_list'] 	=$this->urban_chief_district->query_urban_chief_district_list($_SESSION['user_id'],$search);
		$data['num']						=$this->urban_chief_district->query_urban_chief_district_num($_SESSION['user_id'],$search);
		
		
		
		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}
		
		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_chief_district?".$search_url,$data['num']);
		
		$this->load->view("media/env_urban/env_urban_chief_district",$data);
	}

	public function add_env_urban_chief_district(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_chief_district",$data);
	}

	public function save_env_urban_chief_district(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['government_units'] =trim($this->input->post("government_units"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['subway_station'] =trim($this->input->post("subway_station"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_chief_district");
		$result =$this->urban_chief_district->save_env_urban_chief_district($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_chief_district(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_chief_district");
		$data['env_urban_chief_district_info']=$this->urban_chief_district->query_env_urban_chief_district($env_id);


		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"chief_district","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"chief_district","led");

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_chief_district_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_chief_district_info']['province']);
		}
		if($data['env_urban_chief_district_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_chief_district_info']['city']);
		}
		$this->load->view("media/env_urban/query_env_urban_chief_district",$data);
	}
	public function edit_env_urban_chief_district(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_chief_district");
		$data['env_urban_chief_district_info']=$this->urban_chief_district->query_env_urban_chief_district($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_chief_district_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_chief_district_info']['province']);
		}
		if($data['env_urban_chief_district_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_chief_district_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_chief_district",$data);
	}

	public function update_env_urban_chief_district(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}

		$env_id =$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['government_units'] =trim($this->input->post("government_units"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['hotel'] =trim($this->input->post("hotel"));
		$env['subway_station'] =trim($this->input->post("subway_station"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_chief_district");
		$result =$this->urban_chief_district->update_env_urban_chief_district($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_env_urban_chief_district(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("env/urban_chief_district");
		$env_id =$this->input->get('env_id');
		$this->urban_chief_district->delete_env_urban_chief_district($env_id);
		echo "<script>history.go(-1)</script>";
	}



	public function env_urban_industrial(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		$data['query_urban_env']	=false;
		if ($this->right_manage->check_right("query_urban_env")) {
			$data['query_urban_env']	=true;
		}
		$data['delete_urban_env']	=false;
		if ($this->right_manage->check_right("delete_urban_env")) {
			$data['delete_urban_env']=true;
		}
		$data['add_urban_env']	=false;
		if ($this->right_manage->check_right("add_urban_env")) {
			$data['add_urban_env']	=true;
		}
		$data['update_urban_env']	=false;
		if ($this->right_manage->check_right("update_urban_env")) {
			$data['update_urban_env']	=true;
		}
		$data['assign_excellent_media']	=false;
		if ($this->right_manage->check_right("assign_excellent_media")) {
			$data['assign_excellent_media']	=true;
		}
		$search['province'] 	= $this->input->get("province");
		$search['city']			= $this->input->get("city");
		$search['region'] 		= $this->input->get("region");
		$search['keyword'] 		= $this->input->get("keyword");
		
		
		$this->load->library("env/urban_industrial");
		$data['urban_industrial_list'] 	=$this->urban_industrial->query_urban_industrial_list($_SESSION['user_id'],$search);
		$data['num']					=$this->urban_industrial->query_urban_industrial_num($_SESSION['user_id'],$search);
		
		
		
		$this->load->library("sys/region");
		$data['province_list']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['city_list'] =null;
		$data['region_list'] =null;
		if($search['province']){
			$data['city_list'] =$this->region->get_regions($search['province']);
		}
		if($search['city']){
			$data['region_list'] =$this->region->get_regions($search['city']);
		}
		
		$data['search']=$search;
		$search_url =format_search_url($search);
		$this->load->library("tools/pagination");
		$data['page_link']=$this->pagination->get_pagination(base_url()."index.php/media_env_urban_manage/env_urban_industrial?".$search_url,$data['num']);
		
		$this->load->view("media/env_urban/env_urban_industrial",$data);
	}

	public function add_env_urban_industrial(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);

		$this->load->view("media/env_urban/add_env_urban_industrial",$data);
	}

	public function save_env_urban_industrial(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("add_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['industrial_area'] =trim($this->input->post("industrial_area"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['industrial_nature'] =trim($this->input->post("industrial_nature"));
		$env['enterprise_num'] =intval($this->input->post("enterprise_num"));
		$env['enterprise'] =trim($this->input->post("enterprise"));
		$env['market'] =trim($this->input->post("market"));
		$env['shopping_store'] =trim($this->input->post("shopping_store"));

		$env['create_by'] =$_SESSION['user_name'];
		$env['create_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_industrial");
		$result =$this->urban_industrial->save_env_urban_industrial($env);
		$this->load->helper("common");
		echo JSON($result);
	}

	public function query_env_urban_industrial(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_industrial");
		$data['env_urban_industrial_info']=$this->urban_industrial->query_env_urban_industrial($env_id);


		$this->load->library("media/media");
		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"industrial","common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,"industrial","led");

		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_industrial_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_industrial_info']['province']);
		}
		if($data['env_urban_industrial_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_industrial_info']['city']);
		}
		$this->load->view("media/env_urban/query_env_urban_industrial",$data);
	}
	public function edit_env_urban_industrial(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$env_id =$this->input->get("env_id");
		$this->load->library("env/urban_industrial");
		$data['env_urban_industrial_info']=$this->urban_industrial->query_env_urban_industrial($env_id);


		$this->load->library("sys/region");
		$data['top_regions']	= $this->region->query_user_top_regions($_SESSION['user_id']);
		$data['second_regions'] =null;
		$data['last_regions']	=null;
		if($data['env_urban_industrial_info']['city']){
			$data['second_regions'] =$this->region->get_regions($data['env_urban_industrial_info']['province']);
		}
		if($data['env_urban_industrial_info']['region']){
			$data['last_regions'] =$this->region->get_regions($data['env_urban_industrial_info']['city']);
		}
		$this->load->view("media/env_urban/edit_env_urban_industrial",$data);
	}

	public function update_env_urban_industrial(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}
		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("update_urban_env",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();
		}

		$env_id =$this->input->post("env_id");
		$env['env_name'] =trim($this->input->post("env_name"));
		$env['province'] =trim($this->input->post("province"));
		$env['city'] =trim($this->input->post("city"));
		$env['region'] =trim($this->input->post("region"));
		$env['location'] =trim($this->input->post("location"));
		$env['distribution_map'] =trim($this->input->post("distribution_map"));
		$env['sketch_map'] =trim($this->input->post("sketch_map"));
		$env['industrial_area'] =trim($this->input->post("industrial_area"));
		$env['main_road'] =trim($this->input->post("main_road"));
		$env['industrial_nature'] =trim($this->input->post("industrial_nature"));
		$env['enterprise_num'] =intval($this->input->post("enterprise_num"));
		$env['enterprise'] =trim($this->input->post("enterprise"));
		$env['market'] =trim($this->input->post("market"));
		$env['shopping_store'] =trim($this->input->post("shopping_store"));

		$env['modify_by'] =$_SESSION['user_name'];
		$env['modify_time'] =date("Y-m-d H:i:s");
		$this->load->library("env/urban_industrial");
		$result =$this->urban_industrial->update_env_urban_industrial($env,$env_id);
		$this->load->helper("common");
		echo JSON($result);
	}
	public function delete_env_urban_industrial(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();


		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("query_urban_env",$_SESSION['user_id'])) {
			$this->load->library("common/user_menu");
			$data['user_menu']=$this->user_menu->get_user_menu();
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}

		$this->load->library("env/urban_industrial");
		$env_id =$this->input->get('env_id');
		$this->urban_industrial->delete_env_urban_industrial($env_id);
		echo "<script>history.go(-1)</script>";
	}



	public function get_env_list(){
		$type_name =$this->input->get("type_name");
		$region =$this->input->get("region");
		if ($type_name=="road"){
			$this->load->library("env/urban_road");
			$env_list =$this->urban_road->get_env_list($region);
			echo json_encode($env_list);
		}else {
			$this->load->library("env/urban_circle");
			$env_list =$this->urban_circle->get_env_list($type_name,$region);
			echo json_encode($env_list);
		}
	}

	public function assgin_excellent_media(){

		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();

		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("assign_excellent_media",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			$this->load->view("common/error_tip",$data);
			return;
		}


		$env_type =$this->input->get("env_type");
		$env_id =$this->input->get("env_id");
		if ($env_type=="circle") {
			$this->load->library("env/urban_circle");
			$data['env_urban_info']=$this->urban_circle->query_env_urban_circle($env_id);
		}elseif ($env_type=="road"){
			$this->load->library("env/urban_road");
			$data['env_urban_info']=$this->urban_road->query_env_urban_road($env_id);

		}elseif ($env_type=="market"){
			$this->load->library("env/urban_market");
			$data['env_urban_info']=$this->urban_market->query_env_urban_market($env_id);

		}elseif ($env_type=="station"){
			$this->load->library("env/urban_station");
			$data['env_urban_info']=$this->urban_station->query_env_urban_station($env_id);

		}elseif ($env_type=="stop"){
			$this->load->library("env/urban_stop");
			$data['env_urban_info']=$this->urban_stop->query_env_urban_stop($env_id);

		}elseif ($env_type=="venues"){
			$this->load->library("env/urban_venues");
			$data['env_urban_info']=$this->urban_venues->query_env_urban_venues($env_id);
		}elseif ($env_type=="cbd"){
			$this->load->library("env/urban_cbd");
			$data['env_urban_info']=$this->urban_cbd->query_env_urban_cbd($env_id);
		}elseif ($env_type=="chief_district"){
			$this->load->library("env/urban_chief_district");
			$data['env_urban_info']=$this->urban_chief_district->query_env_urban_chief_district($env_id);
		}elseif ($env_type=="industrial"){
			$this->load->library("env/urban_industrial");
			$data['env_urban_info']=$this->urban_industrial->query_env_urban_industrial($env_id);
		}

		$this->load->library("media/media");

		$data['common_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,$env_type,"common");
		$data['led_excellent_media_list'] =$this->media->query_env_excellent_media_list($env_id,$env_type,"led");
		$data['common_media_list'] =$this->media->query_env_media_list($env_id,$env_type,"common");
		$data['led_media_list'] =$this->media->query_env_media_list($env_id,$env_type,"led");
		$data['env_type']=$env_type;
		$data['env_id']=$env_id;

		$this->load->view("media/env_urban/assgin_excellent_media",$data);
	}

	public function save_assgin_excellent_media(){
		$this->load->library("common/login_manage");
		if ($this->login_manage->check_login()==false) {
			$data['result']		=false;
			$data['message']	='请您先登录';
			echo json_encode($data);die();
		}

		$this->load->library("common/right_manage");
		if (!$this->right_manage->check_right("assign_excellent_media",$_SESSION['user_id'])) {
			$data['title']		="权限不足";
			$data['message']	="你没有权限使用这个功能。";
			echo json_encode($data);die();

		}
		$env_id =$this->input->post("env_id");
		$env_type =$this->input->post("env_type");
		$common_media =$this->input->post("common_media");
		$led_media =$this->input->post("led_media");
		$this->load->library("media/media");
		$this->media->save_assgin_excellent_media($env_id,$env_type,$common_media,$led_media);
		redirect(base_url()."index.php/media_env_urban_manage/env_urban_".$env_type);
	}
}